package cn.hzking.gjmall.adpters.home;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;
import java.util.Locale;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.activitys.second.WebGoodDetailActivity;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.SkillBean;
import cn.hzking.gjmall.utils.PriceFormatUtils;

/**
 * Created by Administrator on 2018/3/29.
 */

public class SenckillAdapter extends BaseQuickAdapter<SkillBean.DataBean.SecillListBean,BaseViewHolder> {
    private String msId;

    public SenckillAdapter(int layoutResId, @Nullable List<SkillBean.DataBean.SecillListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final SkillBean.DataBean.SecillListBean item) {
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo 需要传秒杀id和秒杀条目spuid
                int itemId = item.getSpuId();
                WebGoodDetailActivity.startActivity(mContext, WebGoodDetailActivity.SEACK, String.valueOf(itemId),msId,"","");
               /* Intent intent = new Intent(mContext, GoodDetailActivity.class);
                intent.putExtra("itemId",String.valueOf(itemId));
                mContext.startActivity(intent);*/
            }
        });
        // helper.addOnClickListener(R.id.category_goodlist_ll);
        ImageView imageView = helper.getView(R.id.goodlist_goodimage);
        TextView goodTypeText = helper.getView(R.id.good_type);
        TextView goodTitle = helper.getView(R.id.goodlist_title);
        TextView goodPrice = helper.getView(R.id.goodlist_price);
        TextView goodOrderPrice = helper.getView(R.id.goodlist_oldprice);
        TextView goodOrderState = helper.getView(R.id.good_state);
        //图片
        Glide.with(mContext).load(Gjmall.getOssHost()+item.getImageUrl()).placeholder(R.mipmap.xiangqing).error(R.mipmap.xiangqing).into(imageView);//图片
        //状态
       goodTypeText.setText(String.valueOf(item.getSellPattern()));//商品状态,是否是商家是自营
        goodTitle.setText(String.valueOf(item.getTitle()));//商品标题
        //新的价格
        String newPriceS = PriceFormatUtils.valueFormatWithTwo(String.valueOf(item.getPrice()));
        goodPrice.setText(String.valueOf(newPriceS));
        //老的价格
        goodOrderPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
        goodOrderPrice.setText(String.format(Locale.CHINA,"¥ %s",String.valueOf(item.getAvecostPrice())));

    }
    public void setMsId(String msId){
        this.msId = msId;
    }
}
